package com.interfaces;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.entity.Task;

/**   
* @Title: TaskDao.java 
* @Package com.interfaces 
* @author 孙梦楠 
* @date 2017年9月4日 下午1:46:19 
* @version V1.0.0   
*/

public interface TaskDao extends JpaRepository<Task, Integer>{
	
	@Transactional
	@Query(value = "SELECT t FROM Task t WHERE t.taskstatus=?1 AND t.isdel=0")
	List<Task> findByTaskstatus(String taskstatus);
	
	
	@Transactional
	@Query(value = "SELECT t FROM Task t WHERE (t.taskname=?1 OR ?1 IS NULL )"
			+ "AND (t.taskstatus=?2 OR ?2 IS NULL )  AND  (t.taskorg=?3) AND (t.tasktype=?4) AND t.isdel=0")
	List<Task> findByCondition(String taskname,String taskstatus,Integer taskorg,String  tasktype);
	
	//删除
	@Transactional
	@Modifying
	@Query("update Task t set t.isdel = 1 where t.taskid = ?1") 
	int deleteTask(Integer taskid);
	
	//更新任务状态   0 未启动 ，1 启动
	@Transactional
	@Modifying
	@Query("update Task t set t.taskstatus = ?2 where t.taskid = ?1") 
	int updateTaskstatus(Integer taskid,String taskstatus);
}
